package com.zwq;
/**
 * @author 曾文强
 * @version 1.0
 * @since 1.8
 */

public class NextDate {
    /**
     * 一月31天.
     */
    public static final int THIRTYONE = 31;
    /**
     * 输入三个参数.
     */
    public static final int THREE = 3;
    /**
     * 年份应大于1900年.
     */
    public static final int NINTYHANDRED = 1900;
    /**
     * 年份应小于2050年.
     */
    public static final int TWITYHANDREDFIFTY = 2050;
    /**
     * 一年有12个月份.
     */
    public static final int TWELVE = 12;
    /**
     * 曾文强输入错误.
     */
    private final String zwq;

    /**
     * 获得zwq.
     * @return 返回zwq字符串的值
     */
    public String getZwq() {
        return zwq;
    }
    /**
     * 构造函数.
     * @param name 名字
     */
    public NextDate(final String name) {
        this.zwq = name;
    }

    /**
     * 返回日期.
     * @param month 月
     * @param day   日
     * @param year  年
     * @return      返回日期字符串String
     */
    public String date(final Object month, final Object day,
                       final Object year) {
        String massage;
        if (month instanceof Integer && day instanceof Integer
                && year instanceof Integer) {
            final int mmonth = Integer.parseInt(month.toString());
            final int mday = Integer.parseInt(day.toString());
            final int myear = Integer.parseInt(year.toString());
            if (checks(mmonth, mday, myear)) {
                massage = check(mmonth, mday, myear);
            } else {
                massage = zwq + "输入错误";
            }
        } else {
            massage = zwq + "输入错误";
        }
        return massage;
    }

    /**
     * 返回日期是否合法.
     * @param mmonth    月
     * @param mday      日
     * @param myear     年
     * @return          返回true或fasle
     */
    public final boolean checks(final int mmonth, final int mday,
                                final int myear) {
        boolean massage;
        if (mmonth >= 1 && mmonth <= TWELVE
                && mday >= 1 || mday <= THIRTYONE
                && myear >= NINTYHANDRED && myear <= TWITYHANDREDFIFTY) {
            massage = true;
        } else {
            massage = false;
        }
        return massage;
    }

    /**
     * 返回第二天日期.
     * @param mmonth    月
     * @param mday      日
     * @param myear     年
     * @return          返回true或fasle
     */
    public final String check(final int mmonth, final int mday,
                              final int myear) {
        String massage;
        if (mday == THIRTYONE && mmonth == TWELVE) {
            massage = (myear + 1) + "年1月1日";
        } else if (mday == THIRTYONE) {
            massage = myear + "年" + (mmonth + 1) + "月1日";
        } else {
            massage = myear + "年" + mmonth + "月" + (mday + 1) + "日";
        }
        return massage;
    }
}
